package com.hava.spring_data;

import com.hava.spring_data.entity.User;
import com.hava.spring_data.repository.MyJdbcTemplateDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by yanfa on 2016/10/24.
 */
public class SpringJdbcMain {
    public static void main(String[] args) throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");

        MyJdbcTemplateDao jdbcTemplateDao = context.getBean("myJdbcTemplateDao", MyJdbcTemplateDao.class);
//        jdbcTemplateDao.createTable();
//        jdbcTemplateDao.insertData();
        System.out.println(jdbcTemplateDao.count());
        for(User user : jdbcTemplateDao.getUserList())
            System.out.println(user.getId());

        System.out.println(jdbcTemplateDao.countOfUsersByFirstName("Meimie"));
        User user = new User();
        user.setFirst_name("Lei");
        System.out.println(jdbcTemplateDao.countOfUsersByFirstName(user));
//        MybatisUserDao dao = context.getBean("mybatisUserDao", MybatisUserDao.class);
//        List<User> userList = dao.getUserList();
//        for (User user: userList) {
//            System.out.println(user.getFirstName() + " " + user.getLastName());
//        }
//
//        User liLei = dao.getUser("Lei");
//        System.out.println("getByFirstName: " + liLei.getFirstName() + " " + liLei.getLastName());

        ((ConfigurableApplicationContext) context).close();
    }
}
